<?php

namespace App\Http\Controllers\WeChat;

use App\Handlers\WechatEventHandle;
use App\Handlers\WechatTextHandle;
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Messages\Message;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class WeChatController extends Controller
{
    private $app;

    public function __construct()
    {
        $this->app = Factory::officialAccount(chatConfig());
    }

    /**
     * @return \Symfony\Component\HttpFoundation\Response
     * @throws \EasyWeChat\Kernel\Exceptions\BadRequestException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     */
    public function serve()
    {
        $server = $this->app->server;
        $server->push(WechatTextHandle::class, Message::ALL);
        $server->push(WechatEventHandle::class, Message::EVENT);
        return $server->serve();
    }

    // http get::uri/create
    public function create()
    {
        return view();
    }

    // http post::uri
    public function store(Request $request)
    {
        return $this->success();
    }

    // http get::uri/id
    public function show($id)
    {
        return view();
    }

    // http get::uri/id
    public function edit($id)
    {
        return view();
    }

    // http put::uri/id
    public function update(Request $request, $id)
    {
        return $this->success();
    }

    // http delete::uri/id
    public function destroy($id)
    {
        return $this->success();
    }
}
